<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8">
    <title>Test Case for 'Window.focus'</title>
    <script>
      var gui = require('nw.gui');
      var win = gui.Window.get();
      var win_c = new Array();
      var win2_clicked = false, win1_clicked = false;
      var test_done = false;

      for (var i = 0; i < 3; i++)
	  win_c[i] = 0;
			  
      localStorage.win1 = 0;

      var win1 = gui.Window.open('index1.html', {
	  'new-instance': true
      });

      var win2 = gui.Window.open('index2.html');
      
      win.on('focus', function() {
          console.log('win');
	      win_c[0]++;
      });

      win2.on('focus', function() {
	  console.log('win2');
	  win_c[2]++;
	  win2_clicked = true;
      });
     
      function focus1() {
	  win1_clicked = true;
	  win_c[1] = localStorage.win1;
      }
      
      function done() {
        if (!win1_clicked  || !win2_clicked) {
          setTimeout(done, 2000);
        } else {
          test_done = true;
        }
      }
     
     done();
    </script>
  </head>
  <body>
    <p id="wait" style="font-size:1.5em">For now you should manually click the button to test the case</p>
    <button onclick="focus1()">You should click this only after you focused win1</button>
    <button onclick="win2.focus()">win2 Focus</button>

    <script src="../res/mocha_util.js"></script>
    <script src="mocha_test.js"></script>
  </body>
</html>
